<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>受控组件 USE</title>
</head>
<body>

<div id="test"></div>

<script src="js/react.development.js" crossorigin></script>
<script src="js/react-dom.development.js" crossorigin></script>
<script src="js/babel.js"></script>
<script type="text/babel">
    class Login extends React.Component {
        // 初始化状态
        state = {
            username:'',
            password:''
        }

        nameChange = (event) => {
            console.log(event.target.value);
            this.setState({username:event.target.value});
        }

        submitCall = (event) => {
            /*阻止表单提交*/
            event.preventDefault();
            console.log(this.state.username);
        }

        render() {
            return (
                <form action="https://www.baidu.com" onSubmit={this.submitCall}>
                    USERNAME: <input onChange={this.nameChange} type="text" name="username"/>
                    PASSWORD: <input type="password" name="password"/>
                    <button>Login</button>
                </form>
            );
        }
    }

    ReactDOM.render(<Login/>, document.getElementById('test'))
</script>
</body>
</html>